package org.jeecg.modules.nikeProject.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.modules.nikeProject.entity.SportsPersonalInfo;
import org.jeecg.modules.nikeProject.entity.SportsProject;
import org.jeecg.modules.nikeProject.entity.vo.CheckInfoVO;
import org.jeecg.modules.nikeProject.entity.vo.PersonalInfoVO;
import org.jeecg.modules.nikeProject.entity.vo.PublicInfoVO;
import org.jeecg.modules.nikeProject.service.ISportsPersonalInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.nikeProject.service.ISportsProjectService;

import org.quartz.SimpleTrigger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: 案例评审-个人基本信息
 * @Author: jeecg-boot
 * @Date:   2024-12-05
 * @Version: V1.0
 */
@Slf4j
@Api(tags="202-案例评审-个人基本信息")
@RestController
@RequestMapping("/personalInfo")
public class SportsPersonalInfoController extends JeecgController<SportsPersonalInfo, ISportsPersonalInfoService> {
	@Autowired
	private ISportsPersonalInfoService sportsPersonalInfoService;
	@Autowired
	private ISportsProjectService sportsProjectService;
	
	/**
	 * 分页列表查询
	 *
	 * @param sportsPersonalInfo
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
//	@AutoLog(value = "案例评审-个人基本信息-分页列表查询")
//	@ApiOperation(value="案例评审-个人基本信息-分页列表查询", notes="案例评审-个人基本信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(SportsPersonalInfo sportsPersonalInfo,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<SportsPersonalInfo> queryWrapper = QueryGenerator.initQueryWrapper(sportsPersonalInfo, req.getParameterMap());
		Page<SportsPersonalInfo> page = new Page<SportsPersonalInfo>(pageNo, pageSize);
		IPage<SportsPersonalInfo> pageList = sportsPersonalInfoService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 * 添加
	 *
	 * @param personalInfoVO
	 * @return
	 */
	@AutoLog(value = "案例评审-个人基本信息-添加")
	@ApiOperation(value="案例评审-个人基本信息-添加", notes="案例评审-个人基本信息-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody PersonalInfoVO personalInfoVO, HttpServletRequest request) {
		String username = JwtUtil.getUserNameByToken(request);
		return sportsPersonalInfoService.savePersonalInfo(personalInfoVO, username);
	}

	 /**
	  * 获取当前登陆用户下的最新的公共信息
	  * @param request
	  * @return
	  */
	 @AutoLog(value = "获取个人公共信息")
	 @ApiOperation(value="获取个人公共信息", notes="获取个人公共信息")
	 @GetMapping(value = "/getPublicInfo")
	 public Result<PublicInfoVO> getPublicInfo(@RequestParam(value = "roleType", required=false) String roleType,
											   HttpServletRequest request){
		String username = JwtUtil.getUserNameByToken(request);
		 return sportsPersonalInfoService.getPublicInfo(username,roleType);
	 }
	
	/**
	 * 编辑
	 *
	 * @param personalInfoVO
	 * @return
	 */
	@AutoLog(value = "案例评审-个人基本信息-编辑")
	@ApiOperation(value="案例评审-个人基本信息-编辑", notes="案例评审-个人基本信息-编辑")
	@PostMapping(value = "/edit")
	public Result<?> edit(@RequestBody PersonalInfoVO personalInfoVO, HttpServletRequest request) {
		String username = JwtUtil.getUserNameByToken(request);
		SportsProject sportsProject = sportsProjectService.getSportsProjectById(personalInfoVO.getPersonalInfo().getProjectId());
		if (CommonConstant.PROJECT_STEP_FINISH.equals(sportsProject.getProjectStep())){
			return Result.error("案例已提交不能编辑！");
		}
		sportsPersonalInfoService.updatePersonalInfo(personalInfoVO, username);
		return Result.OK("编辑成功!");
	}
	
	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
//	@AutoLog(value = "案例评审-个人基本信息-通过id删除")
//	@ApiOperation(value="案例评审-个人基本信息-通过id删除", notes="案例评审-个人基本信息-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		sportsPersonalInfoService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
//	@AutoLog(value = "案例评审-个人基本信息-批量删除")
//	@ApiOperation(value="案例评审-个人基本信息-批量删除", notes="案例评审-个人基本信息-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.sportsPersonalInfoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功！");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
//	@AutoLog(value = "案例评审-个人基本信息-通过id查询")
//	@ApiOperation(value="案例评审-个人基本信息-通过id查询", notes="案例评审-个人基本信息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		SportsPersonalInfo sportsPersonalInfo = sportsPersonalInfoService.getById(id);
		return Result.OK(sportsPersonalInfo);
	}

	/**
	* 导出excel
	*
	* @param request
	* @param sportsPersonalInfo
	*/
	@RequestMapping(value = "/exportXls")
	public ModelAndView exportXls(HttpServletRequest request, SportsPersonalInfo sportsPersonalInfo) {
		return super.exportXls(request, sportsPersonalInfo, SportsPersonalInfo.class, "案例评审-个人基本信息");
	}

	/**
	* 通过excel导入数据
	*
	* @param request
	* @param response
	* @return
	*/
	@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
	public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		return super.importExcel(request, response, SportsPersonalInfo.class);
	}

	 /**
	  * 三要素检查
	  * @param checkInfoVO
	  * @return
	  */
	@PostMapping("/checkPhoneAndIdNumber")
	public Result<?> checkPhoneAndIdNumber(@RequestBody CheckInfoVO checkInfoVO) {
		return sportsPersonalInfoService.checkPhoneAndIdNumber(checkInfoVO);
	}


}
